home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dmalloc.zip / INSTALL.LIB / DMALLOC.H < prev    next >
C/C++ Source or Header  |  1992-11-01  |  7KB  |  202 lines

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /* DMALLOC.H v1.0 for MSC                                                  */
  4. /*                                                                         */
  5. /* (C) 1991-1992 E.Vogelsinger                                    09/01/92 */
  6. /***************************************************************************/
  7.  
  8. #if !defined(_DMALLOC_INCLUDED)
  9. #define _DMALLOC_INCLUDED
  10.  
  11. /* ==== a) Definitions =================================================== */
  12.  
  13. /* Valid values for DML_Setup and DML_Select */
  14. #define SET_OFF        0
  15. #define SET_ON         1
  16.  
  17. #define SET_SAVED      1
  18. #define SET_CORRUPTED  2
  19. #define SET_BOTH       3
  20.  
  21. #define SET_UNCHANGED -1
  22. #define PSZ_UNCHANGED  ((void *)-1)
  23.  
  24. /* Valid values for DML_Breakpoint */
  25. #define BPT_SOFTICE    1
  26. #define BPT_CODEVIEW   2
  27. #define BPT_INT3       3
  28.  
  29. /* Values for Watchpoint */
  30. #define FAR_NULLCHECK  ((void *)0)
  31. #define DATA_NULLCHECK ((void *)1)
  32.  
  33.  
  34. /* ==== b) Macros ======================================================== */
  35.  
  36. /*
  37.  * check if we are really compiling large model
  38.  */
  39.  
  40. #if defined _DMALLOC
  41. # if !defined M_I86LM && !defined M_I86CM
  42. #  undef _DMALLOC
  43. #  pragma message ("DMalloc v.1.0 needs the LARGE memory model!")
  44. #  error *** Abort ***
  45. # endif
  46. #endif
  47.  
  48. /*
  49.  * if DMalloc is switched off, define anything
  50.  * so the compiler would not protest
  51.  */
  52.  
  53. #if !defined _DMALLOC
  54. # define DML_Trigger()
  55. # define DML_Setup(f1,f2,f3)
  56. # define DML_Select(f1,f2,f3,f4,f5,p,l)
  57. # define DML_SaveState(p)
  58. # define DML_RestoreState(p)
  59. # define DML_Watchpoint(p,f)   (1)  /* returns nonzero if ptr is valid     */
  60. # define DML_Savepoint(p,f)    (1)  /* here we must assume it is!          */
  61. # define DML_Breakpoint(f)
  62. # define DML_Disable()
  63. # define DML_Enable()
  64. # define DML_Check()           (0)  /* return no failure - heap is ok      */
  65. # define DML_CheckPop()
  66. # define DML_SAVEAREA(name)
  67.  
  68. #else
  69. /*
  70.  * _DMALLOC is defined
  71.  *
  72.  * say that DMalloc is active
  73.  */
  74.  
  75. # pragma message ("DMalloc heap check enabled")
  76.  
  77.  
  78. /*
  79.  * There is one problem with the __FILE__ macro:
  80.  *
  81.  * Each time __FILE__ is used, the complete pathname
  82.  * of the source file will be included within DGROUP!
  83.  *
  84.  * Solution:
  85.  * Before including DMALLOC.H, insert the following lines:
  86.  *    char * DM_file$ = __FILE__;
  87.  *    #define __DMFILE__
  88.  *
  89.  * Then include DMALLOC.H
  90.  *
  91.  * You cannot use the __FILE__ macro within DMALLOC.H,
  92.  * since it will resolve to the name of the include file!
  93.  *
  94.  */
  95.  
  96. #if !defined __DMFILE__
  97. # pragma message ("DML: Warning - __DMFILE__ undefined!")
  98. # pragma message ("     Multiple strings will be added to DGROUP!")
  99. # pragma message ("     Read explanation in DMALLOC.H or your manual.")
  100. # define DM_file$ __FILE__
  101. #endif
  102.  
  103. /*
  104.  * redefine the malloc function calls to our entry points
  105.  */
  106.  
  107. #define malloc(size)       DM_malloc$(size,DM_file$,__LINE__)
  108. #define free(ptr)          DM_free$(ptr,DM_file$,__LINE__)
  109. #define calloc(cnt,size)   DM_calloc$(cnt,size,DM_file$,__LINE__)
  110. #define realloc(ptr,size)  DM_realloc$(ptr,size,DM_file$,__LINE__)
  111.  
  112. #define _fmalloc(size)     DM_malloc$(size,DM_file$,__LINE__)
  113. #define _ffree(ptr)        DM_free$(ptr,DM_file$,__LINE__)
  114. #define _nmalloc(size)     DM_nmalloc$(size,DM_file$,__LINE__)
  115. #define _nfree(ptr)        DM_nfree$(ptr,DM_file$,__LINE__)
  116. #define _expand(ptr,size)  DM_expand$(ptr,size,DM_file$,__LINE__)
  117.  
  118. /*
  119.  * using DML_Trigger, we want to have information about the
  120.  * source as well
  121.  */
  122. #define DML_Trigger()      DM_Trigger$(DM_file$, __LINE__)
  123.  
  124. /*
  125.  * combine check and popup
  126.  */
  127. #define DML_CheckPop()     if(DML_Check()) DML_Trigger();
  128.  
  129. /*
  130.  * define the buffer variable needed to save the DMalloc state
  131.  */
  132. #define DML_SAVESIZE       (128)
  133. #define DML_SAVEAREA(name) unsigned char name[DML_SAVESIZE]
  134.  
  135. /* ==== c) Typedefs ====================================================== */
  136.  
  137. #if !defined _SIZE_T_DEFINED
  138.   typedef unsigned int size_t;
  139. # define _SIZE_T_DEFINED
  140. #endif
  141.  
  142.  
  143. /* ==== d) Prototypes ==================================================== */
  144.  
  145. void *          DM_malloc$      (size_t   size,
  146.                                  char *   pszFile,
  147.                                  unsigned usLine);
  148. void            DM_free$        (void *   pUnit,
  149.                                  char *   pszFile,
  150.                                  unsigned usLine);
  151. void *          DM_calloc$      (size_t   size,
  152.                                  size_t   count,
  153.                                  char *   pszFile,
  154.                                  unsigned usLine);
  155. void *          DM_realloc$     (void *   pUnit,
  156.                                  size_t   size,
  157.                                  char *   pszFile,
  158.                                  unsigned usLine);
  159. void near *     DM_nmalloc$     (size_t   size,
  160.                                  char *   pszFile,
  161.                                  unsigned usLine);
  162. void            DM_nfree$       (void near * pUnit,
  163.                                  char *   pszFile,
  164.                                  unsigned usLine);
  165. void *          DM_expand$      (void *   pUnit,
  166.                                  size_t   size,
  167.                                  char *   pszFile,
  168.                                  unsigned usLine);
  169. void     pascal DM_Trigger$     (char *   pszFile,
  170.                                  unsigned usLine);
  171.  
  172. void     pascal DML_Setup       (unsigned fAlert,
  173.                                  unsigned fSaved,
  174.                                  unsigned usPopCycles,
  175.                                  unsigned usCheckCycles,
  176.                                  char *   pszOwner,
  177.                                  unsigned usLine);
  178. void     pascal DML_Select      (unsigned fMalloc,
  179.                                  unsigned fMarked,
  180.                                  unsigned fNull,
  181.                                  unsigned fData,
  182.                                  unsigned fSystem,
  183.                                  char     *pszOwner,
  184.                                  unsigned usLine);
  185. void     pascal DML_SaveState   (void *   pSave);
  186. void     pascal DML_RestoreState(void *   pSave);
  187. unsigned pascal DML_Watchpoint  (void far *p,
  188.                                  unsigned fOnOff);
  189. unsigned pascal DML_Savepoint   (void far *p,
  190.                                  unsigned fOnOff);
  191. void     pascal DML_Breakpoint  (unsigned fType);
  192. void     pascal DML_Disable     (void);
  193. void     pascal DML_Enable      (void);
  194. unsigned pascal DML_Check       (void);
  195.  
  196. /* _DMALLOC defined */
  197. #endif
  198.  
  199. /* _DMALLOC_INCLUDED undefined */
  200. #endif
  201.  
  202.